<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit :isheader="isheader">
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">

                        <rx-button alias="formTemplateAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 && removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item
                                    key="1"
                                    @click="editOne"
                                    v-if="editEnable && selectedRowKeys.length > 0"
                                    alias="formRuleEdit"
                                    :butn-type="'primary'"
                                    :show-no-right="false"
                                >
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item
                                    key="2"
                                    @click="delByIds(selectedRowKeys)"
                                    v-if="removeEnable && selectedRowKeys.length > 0"
                                    alias="formRuleDelete"
                                    :butn-type="'danger'"
                                    :show-no-right="false"
                                >
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.temName','模版名称')">
                                    <a-input :placeholder="i18n('form.temName','模版名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="$ti18('rxForm.rxAlias', '别名')">
                                    <a-input :placeholder="$ti18('rxForm.rxAlias', '请输入别名','','input')" v-model="queryParam.Q_ALIAS__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.templateType', '模板类型')">
                                    <a-select :options="templateTypes" v-model="queryParam.Q_TYPE__S_EQ" allowClear></a-select>

                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :bordered="isBorder"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formTemplate/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="type" slot-scope="{ text,record }">{{typeMap[text]}}</span>
                    <span slot="category" slot-scope="{ text,record }">{{categoryMap[text]}}</span>
                    <span slot="genMode" slot-scope="{ text, record }">
                          <a-tag :color="genModeMap[text].color">
                            <span>{{genModeMap[text].text}}</span>
                          </a-tag>
                    </span>
                    <span slot="mainSubType" slot-scope="{ text, record }">
                          <a-tag :color="mainSubTypeMap[text].color">
                            <span>{{mainSubTypeMap[text].text}}</span>
                          </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                      </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
    import FormTemplateApi from '@/api/form/core/formTemplate'
    import FormTemplateEdit from './FormTemplateEdit'
    import {BaseList} from "@lowcode/jpaas-common-lib";

    export default {
        name: 'FormTemplateList',
        mixins: [BaseList],
        created() {
            this.needFilterAppId();
        },
        computed:{
            templateTypes(){
                let types=[];
                for(let key in this.typeMap){
                    types.push({value:key,label:this.typeMap[key]})
                }
                return types;
            }
        },
        data() {
            return {
                //显示搜索
                showSearch: true,
                typeMap: {
                    pc: this.i18n('list.pcTem','pc模板'),
                    list: this.i18n('list.listTem','列表模板'),
                    mobile: this.i18n('list.phoneTem','手机模板'),
                    print: this.i18n('list.printTem','打印模板'),
                    codeGen: this.i18n('list.codeGen','代码生成'),
                },
                categoryMap: {
                    main: this.i18n('list.masterTable','主表'),
                    onetoone: this.i18n('list.oneToOne','子表一对一'),
                    onetomany: this.i18n('list.oneToMany','子表一对多'),
                    field: this.i18n('list.field','字段'),
                    opinion: this.i18n('list.opinion','字段'),
                },
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type: 'indexColumn',
                        width: 40,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'}
                    },
                    {title: this.i18n('form.temName','模版名称'), dataIndex: 'name', width: 100},
                    {title: this.$ti18('rxForm.rxAlias', '别名'), dataIndex: 'alias', width: 100},
                    {title: this.i18n('form.templateType','模版类型'), dataIndex: 'type', width: 100, scopedSlots: {customRender: 'type'}},
                    {title: this.i18n('form.entityType','实体生成类型'), dataIndex: 'genMode', width: 100, scopedSlots: {customRender: 'genMode'}},
                    {title: this.i18n('form.mode','模式'), dataIndex: 'mainSubType', width: 100, scopedSlots: {customRender: 'mainSubType'}},
                    {title: this.i18n('form.category','类别'), dataIndex: 'category', width: 60, scopedSlots: {customRender: 'category'}},
                    {title: this.$ti18('rxList.action','操作'), width: 60, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
                ],
                component: FormTemplateEdit,
                comment: this.i18n('list.formTem','表单模版'),
                genModeMap: {
                    "genCode": {color: 'green', text: this.i18n('default','默认')},
                    "form": {color: 'green', text: this.i18n('onLineForm','在线表单')},
                    "db": {color: 'red', text: this.i18n('tableMap','物理表映射')},
                    "create": {color: 'red', text: this.i18n('mancreate','手动创建')},
                    "": {color: 'red', text: this.i18n('list.nothing','无')}
                },
                mainSubTypeMap: {
                    "mainSub": {color: 'green', text: this.i18n('master','主从')},
                    "mainAloneSub": {color: 'red', text: this.i18n('masterSepare','主从分离')},
                    "": {color: 'red', text: this.i18n('list.nothing','无')}
                },
            }
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "formTemplate", key);
            },
            delById(ids) {
                return FormTemplateApi.del({ids: ids.join(',')});
            },
            getListByParams(parameter) {
                return FormTemplateApi.query(parameter)
            },
            search() {
                this.$refs.table.loadData();
            },
            cancel() {
                this.resetSearch();
            },
            closeSearchbar() {
                //关闭过滤弹窗；（点击X触发）
                this.fitSearch = false;
            }
        }
    }
</script>
<style scoped>

</style>

